from django.shortcuts import render
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.generics import CreateAPIView
from .models  import *
from .serializers import CreateUserSerializer


# 判断用户是否存在
class UsernameCountView(APIView):
    def get(self,request,username):

        count = User.objects.filter(username = username).count()

        data = {
            'username':username,
            'count':count,
        }

        return Response(data)
# 判断电话是否存在
class MobileCountView(APIView):
    def get(self,request,mobile):

        count = User.objects.filter(mobile = mobile).count()

        data = {
            'username':mobile,
            'count':count,
        }

        return Response(data)

# 注册用户
class CreateUserView(CreateAPIView):
    serializer_class = CreateUserSerializer




